/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package db;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Bryan
 */
public class AddTerms extends HttpServlet {

    /**
    
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    
    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     * 
     */
    /**
     * Adds a new term into the database
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
         Connection con = DBConnector.connect();
        String  checkid = null;
        
        try{
        String terms = request.getParameter("terms");
        String clienttype = request.getParameter("clienttype");
        
        String interest = request.getParameter("interest");
        String servicecharge=request.getParameter("servicecharge");
        String notary = request.getParameter("notaryfee");
        String evat = request.getParameter("evat");
        String docs = request.getParameter("docs");
        String collectionfee = request.getParameter("collectionfee");
        String processingfee = request.getParameter("processingfee");
        String bank=request.getParameter("bank");
        String lbc = request.getParameter("lbc");
        String cashbound = request.getParameter("cashbound");
        String lending = request.getParameter("lending");
        String commission = request.getParameter("commission");
        
            
                PreparedStatement ps = con.prepareStatement
                ("insert into quicklenddb.terms(terms,clienttype,"
                        + "less_ui,service_charge,notary_fee,evat,docs,collectionfee,"
                        + "processingfee,bank_charge,lbc_charge,cashbound,lending,commission) "
                        + "values(?,?,(?/100),(?/100),?,(?/100),(?/100),(?/100),(?/100),?"
                        + ",?,?,?,(?/100))");
                
                
                ps.setString(1, terms);
                ps.setString(2, clienttype);
                ps.setString(3, interest);
                ps.setString(4, servicecharge);
                ps.setString(5, notary);
                ps.setString(6, evat);
                ps.setString(7, docs);
                ps.setString(8, collectionfee);
                ps.setString(9, processingfee);
                ps.setString(10, bank);
                ps.setString(11, lbc);
                ps.setString(12, cashbound);
                ps.setString(13, lending);
                ps.setString(14, commission);
                
                
                ps.executeUpdate();
                
               
          
                response.sendRedirect("terms.jsp");
            
            
        }catch(SQLException e)
        {
            System.out.println(e); 
            response.sendRedirect("fail.jsp");
            //Logger.getLogger(RegisterServlet.class.getName()).log(Level.SEVERE, null, e);
        }
    }

    

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
